//首页头部焦点图
var swiper = new Swiper('.swiper-container',{
	followFinger : false,
	speed:800,
	pagination : {
		el:'.swiper-pagination',
	},
	on:{
		  init: function(){
			swiperAnimateCache(this); //隐藏动画元素 
			swiperAnimate(this); //初始化完成开始动画
		  }, 
		  slideChangeTransitionEnd: function(){ 
			swiperAnimate(this); //每个slide切换结束时也运行当前slide动画
			//this.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); 动画只展现一次，去除ani类名
		  } 
		}
});

//竞价投放
var mySwiper = new Swiper('.bidding', {
	slidesPerView: 3,
	spaceBetween: 0,
	centeredSlides: true,
	loop: true,
	navigation: {
		nextEl: '.bidding-next',
		prevEl: '.bidding-prev',
	},
})

//详情图片切换
var mySwiper = new Swiper('.detail-photo', {
  slidesPerView:1,
  spaceBetween: 0,
  centeredSlides: true,
  loop: true,
  navigation: {
  	nextEl: '.detail-next',
  	prevEl: '.detail-prev',
  }
});

 var galleryThumbs = new Swiper('.gallery-thumbs', {
      spaceBetween: 10,
      slidesPerView: 4,
      freeMode: true,
      watchSlidesVisibility: true,
      watchSlidesProgress: true,
    });
    var galleryTop = new Swiper('.gallery-top', {
      spaceBetween: 0,
      navigation: {
        nextEl: '.detail-next',
        prevEl: '.detail-prev',
      },
      thumbs: {
        swiper: galleryThumbs
      }
    });

//倒计时
layui.use('util', function(){
  var util = layui.util;
  serverTime = new Date().getTime(); //假设为当前服务器时间，这里采用的是本地时间，实际使用一般是取服务端的 
  var endTime = new Date(2020,6,1).getTime() //假设为结束日期
  util.countdown(endTime, serverTime, function(date, serverTime, timer){
	var str = '<span>'+date[0]+'</span>'+'天'+'<span>'+date[1]+'</span>'+'时'+'<span>'+date[2]+'</span>'+'分'+'<span>'+date[3]+'</span>'+'秒';
	layui.$('#count').html('距结束：'+ str);
	if ( (date[0]+date[1]+date[2]+date[3]) <=0  ) {
		layui.$('#count').html('竞拍已结束');
	}
  });  
  
});

//滚动动画
var isScroll = {
    /*初始化*/
    init: function (_el) {
        this.start(_el);
        $(window).on('scroll', function () {
            isScroll.start(_el)
        });
    },
    /*开始*/
    start: function (_el) {
        var self = this;
        $(_el).each(function () {
            var _self = $(this);
            /*滚动高度*/
            var isScrollTop = $(window).scrollTop();
            /*滚动视度*/
            var isWindowHeiget = $(window).height() *0.8;
            /**/
            var _class = $(this).data('animation');
            if (isScrollTop + isWindowHeiget > $(this).offset().top) {
                _self.addClass(_class);
            }
        });
    }
}

//初始化滚动动画
$(document).ready(function () {
	isScroll.init('.animated');
});

//监听导航滚动到顶部浮动
$(window).scroll(function () {
	if($(window).scrollTop()>($('.media-header').height())){
		$('.media-header').addClass('topfixed');
	}else{
		$('.media-header').removeClass('topfixed');
	}

});

$(function() {
	
	//提示框
    function tips(divObj, aobj) {
        var myDiv = $(divObj);
        $(aobj).mouseover(function(event) {
            $(divObj).fadeIn();; //调用显示DIV方法
            $(document).one("mouseover",
            function() { //对document绑定一个影藏Div方法
                $(divObj).hide();
            });
            event.stopPropagation(); //阻止事件向上冒泡
        });
        $(divObj).mouseover(function(event) {
            event.stopPropagation(); //阻止事件向上冒泡
        });
    }
    tips("#myDiv", ".tips");
    // tips("#myDiv1", "#ah2");
});
